package cn.edu.zut.score.controller.teacher;

import cn.edu.zut.score.core.constant.RoleEnum;
import cn.edu.zut.score.core.domain.PageResponse;
import cn.edu.zut.score.core.domain.RestResponse;
import cn.edu.zut.score.core.dto.request.MarkRequest;
import cn.edu.zut.score.core.dto.request.ReplyAddRequest;
import cn.edu.zut.score.core.dto.request.ReplyInfoPageRequest;
import cn.edu.zut.score.core.dto.request.ReplyPageRequest;
import cn.edu.zut.score.core.dto.response.GradeResponse;
import cn.edu.zut.score.core.dto.response.GroupResponse;
import cn.edu.zut.score.core.dto.response.ReplyInfoResponse;
import cn.edu.zut.score.core.dto.response.ReplyResponse;
import cn.edu.zut.score.core.entity.Info;
import cn.edu.zut.score.service.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zby
 * @date 2021/06/29
 */
@RestController
@RequestMapping("/teacher/reply")
@ApiModel("答辩相关api")
@CrossOrigin
public class TeacherReplyController {

    @Autowired
    private IReplyService iReplyService;

    @Autowired
    private IClazzService iClazzService;

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IGroupInfoService iGroupInfoService;

    @Autowired
    private IReplyInfoService iReplyInfoService;

    @Autowired
    private IGradeService iGradeService;

    @Autowired
    private IGroupService iGroupService;

    @Autowired
    private IMessageService iMessageService;

    @ApiOperation("创建答辩")
    @PostMapping("")
    public RestResponse<ReplyResponse> addReply(@RequestBody ReplyAddRequest replyAddRequest) {
        return iReplyService.addReply(replyAddRequest);
    }

    @ApiOperation("分页获取当前用户答辩")
    @PostMapping("/list")
    public RestResponse<PageResponse<ReplyResponse>> getAllReplys(@RequestBody ReplyPageRequest replyPageRequest) {
        return iReplyService.getCurrentTeacherAllReplys(replyPageRequest);
    }

    @ApiOperation("获取当前用户所有小组")
    @GetMapping("/group")
    public RestResponse<List<Info>> getAllGroups() {
        return iGroupInfoService.getAllGroups();
    }

    @ApiOperation("获取所有班级")
    @GetMapping("/clazz")
    public RestResponse<List<Info>> getAllClass() {
        return iClazzService.queryAllClasses();
    }

    @ApiOperation("获取所以有学生")
    @GetMapping("/student")
    public RestResponse<List<Info>> getAllStudents() {
        return iUserService.queryAllUsersByRole(RoleEnum.student);
    }

    @ApiOperation("根据ID获取答辩详情")
    @GetMapping("/{replyid}")
    public RestResponse<ReplyResponse> getReplyById(@PathVariable("replyid") Long replyid) {
        return iReplyService.getReplyById(replyid);
    }

    @ApiOperation("根据ID查询答辩")
    @GetMapping("/data/{replyid}")
    public RestResponse<List<Integer>> getDataById(@PathVariable("replyid") Long replyid) {
        return iReplyInfoService.getDataById(replyid);
    }

    @ApiOperation("根据ID查询答辩分页学生列表")
    @PostMapping("/list/{replyid}")
    public RestResponse<PageResponse<ReplyInfoResponse>> getListById(@PathVariable("replyid") Long replyid, @RequestBody ReplyInfoPageRequest replyInfoPageRequest) {
        return iReplyInfoService.getListById(replyid, replyInfoPageRequest);
    }

    @ApiOperation("根据答辩ID及学生Id获取其成绩")
    @GetMapping("/list/{replyid}/{studentid}")
    public RestResponse<List<GradeResponse>> getScoreById(@PathVariable("replyid") Long replyid, @PathVariable("studentid") Long studentid) {
        return iGradeService.getScoreById(replyid, studentid);
    }

    @ApiOperation("获取小组信息")
    @GetMapping("/group/{groupid}")
    public RestResponse<GroupResponse> getGroupById(@PathVariable("groupid") Long groupid) {
        return iGroupService.getGroupById(groupid);
    }

    @ApiOperation("根据答辩ID提醒未预约答辩的学生")
    @PostMapping("/remind/{replyid}")
    public RestResponse<String> remindInline(@PathVariable("replyid") Long replyId) {
        return iReplyInfoService.remindInline(replyId);
    }

    @ApiOperation("开始答辩学生")
    @PostMapping("/begin/{replyId}/{studentId}")
    public RestResponse<String> beginReply(@PathVariable("replyId") Long replyId, @PathVariable("studentId") Long studentId) {
        return iReplyInfoService.beginReply(replyId, studentId);
    }

    @ApiOperation("推送答辩评分")
    @PostMapping("/push/{replyId}/{studentId}")
    public RestResponse<String> pushMark(@PathVariable("replyId") Long replyId, @PathVariable("studentId") Long studentId) {
        return iMessageService.pushMarkMessage(replyId, studentId);
    }

    @ApiOperation("评分")
    @PostMapping("/mark")
    public RestResponse<String> mark(@RequestBody MarkRequest markRequest) {
        return iGradeService.mark(markRequest);
    }

    @ApiOperation("获取答辩总体成绩分析")
    @PostMapping("/analyse/scale/{replyid}")
    public RestResponse<List<Double>> analyseScale(@PathVariable("replyid") Long replyId) {
        return iGradeService.analyseScale(replyId);
    }

    @ApiOperation("获取答辩某个学生成绩分析")
    @PostMapping("/analyse/student/{replyid}/{studentid}")
    public RestResponse<List<Double>> analyseStudent(@PathVariable("replyid") Long replyId, @PathVariable("studentid") Long studentId) {
        return iGradeService.analyseStudent(replyId, studentId);
    }
}
